package com.itheima.controller;

import com.itheima.pojo.NursingProject;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.queryParams.NursingProjectParam;
import com.itheima.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    //条件分页查询
    @GetMapping
    public Result findAll(NursingProjectParam nursingProjectParam){
        PageResult pageResult = nursingProjectService.getList(nursingProjectParam);
        return Result.success(pageResult);
    }

    //新增护理项目
    @PostMapping
    public Result addNursingProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.save(nursingProject);
        return Result.success();
    }

    //回显查询
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return Result.success(nursingProject);
    }

    //修改
    @PutMapping
    public Result updateById(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateById(nursingProject);
        return Result.success();
    }

    //删除
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        nursingProjectService.removeById(id);
        return Result.success();
    }

    //查询所有
    @GetMapping("/all")
    public Result queryAll(){
        List<NursingProject> list = nursingProjectService.list();
        return Result.success(list);
    }
}
